<template>
  <div class="loginInfo">
    <span>您好！{{userName}}</span>
    <el-button type="primary" @click="logout">登出</el-button>
  </div>
</template>

<script>
  import {cookieStorage, localStorage, sessionStorage} from 'common/storage'

  export default {
    data() {
      return {
        userName: "",
      }
    },
    created() {
      this.userName = this.getUserName();
    },
    methods: {
      getUserName() {
        var name = localStorage.get("name");
        return name;
      },
      logout() {
        this.setCookie("username", "", -1);
        this.setCookie("id", "", -1)
        this.$router.push('/login');
      },
      setCookie(c_name, value, expiredays) {
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + expiredays);
        document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
      }
      ,
    },

  }
</script>
<style>
  .loginInfo {
    float: right;
    margin-top: 15px;
    margin-right: 240px;
    cursor: pointer;
    color: #28ccaa;
  }

</style>
